<?php
// +----------------------------------------------------------------------
// | OneThink [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013 http://www.onethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: 麦当苗儿 <zuojiazi@vip.qq.com>
// +----------------------------------------------------------------------

namespace Home\Model;
use Think\Model;
/**
 * 配置模型
 * @author 麦当苗儿 <zuojiazi@vip.qq.com>
 */

class IndexModel extends Model {
	
	protected $trueTableName = 'bhy_article';
	
    protected $_validate = array(
        array('name', 'require', '姓名不能为空!', self::EXISTS_VALIDATE, 'regex', self::MODEL_BOTH),
        array('mobile', 'require', '电话不能为空!', self::EXISTS_VALIDATE, 'regex', self::MODEL_BOTH),
        array('email', 'require', '邮箱不能为空!', self::EXISTS_VALIDATE, 'regex', self::MODEL_BOTH),
        array('content', 'require', '内容不能为空!', self::EXISTS_VALIDATE, 'regex', self::MODEL_BOTH),
    );



    public function getTree($id = 0, $field = true){
        /* 获取当前分类信息 */
       /* if($id){
            $info = $this->info($id);
            $id   = $info['id'];
        }*/

        /* 获取所有分类 */
        $map  = array('status' => array('gt', -1));
        $list = $this->field($field)->where($map)->order('sort')->select();
        $list = list_to_tree($list, $pk = 'id', $pid = 'pid', $child = 'sonlist', $root = $id);

        /* 获取返回数据 */
        if(isset($info)){ //指定分类则返回当前分类极其子分类
            $info['_'] = $list;
        } else { //否则返回所有分类
            $info = $list;
        }

        return $info;
    }
   

}
